import java.util.Stack;

public class Solution1047 {
    public String removeDuplicates(String s) {
        Stack<Character> stack=new Stack<>();
        for (char c : s.toCharArray()) {
            if (stack.isEmpty()){
                stack.push(c);
            }else{
                if (c==stack.peek()){
                    stack.pop();
                }else{
                    stack.push(c);
                }
            }
        }
        StringBuilder stringBuilder=new StringBuilder();
        for (Character character : stack) {
            stringBuilder.append(character);
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        System.out.println(new Solution1047().removeDuplicates("abbaca"));
    }
}
